//
//  FaceIDLoginVC.swift
//  ZYA
//
//  Created by 邱仙凯 on 2024/5/17.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
 class FaceIDLoginVC: UIViewController {
     var faceresultClo:((Bool)->())?
     var loginName : UILabel = {
         let v = UILabel()
         v.text = "用户名"
         v.font = UIFont.boldSystemFont(ofSize: 18)
         return v
     }()
     var faceBtn : UIButton = {
         let v = UIButton()
         v.setBackgroundImage(UIImage(named: "faceidbtn"), for: .normal)
         return v
     }()
     var logintip : UIButton = {
         let v = UIButton()
         v.setTitleColor(UIColor(kshex: "87CEFA"), for: .normal)
         v.setTitle("点击登录", for: .normal)
         return v
     }()
     var loginguarantee : UILabel = {
         let v = UILabel()
         v.font = UIFont.systemFont(ofSize: 15)
         v.textColor = .lightGray
         v.numberOfLines = 0
         v.text = "您在当前设备的面容ID将用于该设备的身份验证，我们仅接收面容ID的验证结果，并不收集您的面容ID信息"
         return v
     }()
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
         self.startFace()
     }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = "登录"
        
        self.view.addSubview(loginName)
        self.view.addSubview(faceBtn)
        self.view.addSubview(logintip)
        self.view.addSubview(loginguarantee)
        let uname = UserDefaults.standard.object(forKey: FaceIDUsername) as? String
        loginName.text = uname
        loginName.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(120)
            make.centerX.equalToSuperview()
        }
        faceBtn.snp.makeConstraints { make in
            make.width.height.equalTo(100)
            make.centerX.equalToSuperview()
            make.top.equalTo(loginName.snp.bottom).offset(80)
        }
        logintip.snp.makeConstraints { make in
            make.top.equalTo(faceBtn.snp.bottom).offset(20)
            make.width.equalTo(100)
            make.height.equalTo(32)
            make.centerX.equalToSuperview()
        }
        loginguarantee.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-100)
            make.width.equalToSuperview().multipliedBy(0.8)
            make.centerX.equalToSuperview()
        }
        logintip.addTouchUpInSideAction { _ in
            self.startFace()
        }
        faceBtn.addTouchUpInSideAction { _ in
            self.startFace()
        }
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", style: .done, target: self, action: #selector(dismiss_a))
       
        
        
    }
     func startFace() {
         FaceIdTool.shared.openFaceIdAction { flag,tipstr in
             if flag {
                 self.dismiss_a()
              }
             if let clo = self.faceresultClo {
                 clo(flag)
             }
            
         }
     }
    
     
    @objc func dismiss_a() {
        self.dismiss(animated: true, completion: nil)
        
    }
}

 
